package com.socene.kotlin.config

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.HttpMessageConverter
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter

/**
 *Created by: Sorata 2017/9/9 下午4:10
 *
 */
@Configuration
class WebMvcConfiguration @Autowired constructor(@Qualifier("fastJsonHttpMessageConverter4") val fastConverter: FastJsonHttpMessageConverter4) : WebMvcConfigurerAdapter() {


    override fun configureMessageConverters(converters: MutableList<HttpMessageConverter<*>>?) {
        converters?.add(fastConverter)
        super.configureMessageConverters(converters)
    }

    override fun addResourceHandlers(registry: ResourceHandlerRegistry?) {
        super.addResourceHandlers(registry)
        registry?.addResourceHandler("/**")?.addResourceLocations("classpath:/static/")
        registry?.addResourceHandler("swagger-ui.html")
                ?.addResourceLocations("classpath:/META-INF/resources/")
        registry?.addResourceHandler("/webjars/**")
                ?.addResourceLocations("classpath:/META-INF/resources/webjars/")
    }
}